<template>
  <a-drawer
    title="新增复试人员数"
    width=350
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="peopleAddVisible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-form :form="form">
      <a-row :gutter="48">
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='院系'>
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-decorator="['ssyxm',{initialValue:postParams.ssyxm}]" @change="yxChange">
                    <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwmc }}</a-select-option>
                  </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='专业'>
            <a-select :allowClear="true" showSearch optionFilterProp="children" v-decorator="['sszym',{initialValue:postParams.sszym}]">
                 <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zymc }}</a-select-option>
              </a-select>
      </a-form-item>
        </a-col>
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='教授人数' >
            <a-input-number v-decorator="['jsrs',{initialValue:postParams.jsrs}]" />
        </a-form-item>
        </a-col>
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='非教授人数' >
            <a-input-number v-decorator="['fjsrs',{initialValue:postParams.fjsrs}]"/>
        </a-form-item>
        </a-col>
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='讲师人数' >
            <a-input-number v-decorator="['jsrys',{initialValue:postParams.jsrys}]"/>
        </a-form-item>
        </a-col>
        <a-col :sm="{span:12}"  :md="{span:12}">
            <a-form-item label='其他人员' >
            <a-input-number v-decorator="['qtrys',{initialValue:postParams.qtrys}]"/>
        </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <div class="drawer-bootom-button">
      <a-button style="margin-right: .8rem" @click="onClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary" :loading="loading">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const formItemLayout = {
  labelCol: { span: 3 },
  wrapperCol: { span: 18 }
}

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']
export default {
  name: 'DepartmentsAdd',
  props: {
    peopleAddVisible: {
      default: false
    }
  },
  components: {
    STable
  },
  data () {
    return {
      formItemLayout,
      loading: false,
      postParams: {
        fjsrs: '',
        jsrs:'',
        jsrys:'',
        qtrys:'',
        ssyxm:'',
        sszym:''
      },
      // 表头
      columns: [
        {
          title: '',
          dataIndex: 'column'
        },
        {
          title: '计划',
          scopedSlots: { customRender: 'plan' }
        },
        {
          title: '已分配',
          dataIndex: 'distribution'
        }
      ],
      selectMenu: {
        yx: [], // 院系
        zy:[]
      }
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
    },
    reset () {
    },
     // 选择院系
     yxChange (code) {
       this.$set(this.postParams, 'sszym', '')
       this.$api.base.majorAll({lsdwh: code}).then(res => {
         this.$set(this.selectMenu, 'zy', res.data)
       })
     },
    // 关闭
    onClose () {
      this.reset()
      this.$emit('close')
    },
    // 保存
    handleSubmit () {
      this.form.validateFields( (err,values) => {
        if(err){
          this.$message.error("请选择必填项")
        }else{
           this.$api.recruitstat.reExamPersonManageAdd(this.form.getFieldsValue()).then(res => {
            this.$emit('success')
          }).finally(() => {
            this.loadingBtn = false
          })
        }
      })
    }
  }
}
</script>
